/*
 * Copyright (C) 2007 Eskil Bylund
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

using System;
using System.Collections;

using DCSharp.Hashing;

namespace DCSharp.Backend.Objects
{
	// FIXME: Does the name of the class make sense?
	// FIXME: What additional data is needed by ISegmentStrategy implementations to intelligently create segments?
	/// <summary>
	/// Contains the information required for creating segments for a file.
	/// </summary>
	public class SegmentedFileInfo
	{
		private RemoteFileInfo remoteFile;
		private HashTree hashTree;
		private BitArray completed;
		private BitArray active;

		public SegmentedFileInfo(RemoteFileInfo remoteFile, HashTree hashTree,
			BitArray completed, BitArray active)
		{
			this.remoteFile = remoteFile;
			this.hashTree = hashTree;
			this.completed = completed;
			this.active = active;
		}

		public RemoteFileInfo RemoteFile
		{
			get { return remoteFile; }
		}

		public HashTree HashTree
		{
			get { return hashTree; }
		}

		public BitArray Completed
		{
			get { return completed; }
		}

		public BitArray Active
		{
			get { return active; }
		}
	}

	/// <summary>
	/// Represents a segment of a file.
	/// </summary>
	public class Segment
	{
		private long start;
		private long position;
		private long end;

		public Segment(long start, long end)
		{
			if (start < 0)
			{
				throw new ArgumentOutOfRangeException("start");
			}
			if (end <= start)
			{
				throw new ArgumentOutOfRangeException("end");
			}
			this.start = start;
			this.position = start;
			this.end = end;
		}

		public long Start
		{
			get { return start; }
		}

		public long Position
		{
			get { return position; }
			set { position = value; }
		}

		public long End
		{
			get { return end; }
		}
	}
}
